package com.edu.exam.entity.auth;

import com.edu.exam.enums.common.Gender;
import com.edu.exam.enums.student.EnrollmentStatus;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import java.time.LocalDate;

/**
 * 学生用户实体类
 * 对应数据库表：student_user
 * 管理学生用户信息，包括学号、专业、班级等学生特有属性
 * 支持学生信息的创建、查询、更新和学籍状态管理
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Table(name = "student_user")
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class StudentUser extends BaseUser {

    @NotBlank(message = "学号不能为空")
    @Pattern(regexp = "^\\d{8,20}$", message = "学号格式不正确")
    @Column(name = "student_number", unique = true, nullable = false, length = 20)
    private String studentNumber;

    @NotBlank(message = "身份证号不能为空")
    @Pattern(regexp = "^\\d{17}[\\dX]$", message = "身份证号格式不正确")
    @Column(name = "id_card", unique = true, nullable = false, length = 18)
    private String idCard;

    @Column(name = "birth_date")
    private LocalDate birthDate;

    @Enumerated(EnumType.STRING)
    @Column(name = "gender", length = 10)
    private Gender gender;

    @Column(name = "class_id")
    private Long classId;

    @Column(name = "enrollment_date")
    private LocalDate enrollmentDate;

    @Column(name = "graduation_date")
    private LocalDate graduationDate;

    @Enumerated(EnumType.STRING)
    @Column(name = "enrollment_status", length = 20)
    private EnrollmentStatus enrollmentStatus = EnrollmentStatus.ENROLLED;

    /**
     * 获取用户类型标识
     * @return 学生用户类型标识
     */
    @Override
    public String getUserType() {
        return "STUDENT";
    }
}